﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipCo.Data;
using VipCo.Entities;

public partial class Diem_chap_nhan : System.Web.UI.Page
{
    // Khai bao bien toan cuc
    private static int IdTpG = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["TP"] != null)
        {
            string strTp = Session["TP"].ToString();
            HienthiDiadiem();
        }
        else
        {
            Session["TP"] = Common.TP_Danang;
            HienthiDiadiem();
        }
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    /// <summary>
    /// Hien thi du lieu dia diem theo tung chuyen muc
    /// </summary>
    public void HienthiDiadiem()
    {
        // Lay danh sach tat ca cac danh muc diem den
        TList<NhomChuyenMuc> listNcm = DataRepository.NhomChuyenMucProvider.GetAll();

        // Kiem tra xem co bao nhieu nhom chuyen muc roi bat dau duyet va lay danh sach 4 Dia diem 
        // thuoc moi chuyen muc.
        if (listNcm.Count() > 0)
        {
            StringBuilder stringDanhmuc = new StringBuilder(); // tag cac danh muc
            StringBuilder stringBuilder = new StringBuilder(); // danh sach cac dia diem

            stringDanhmuc.Append("<div class=\"tag-diadiem\">");

            foreach (var nhomChuyenMuc in listNcm)
            {
                // 
                stringDanhmuc.Append("<a href=\"#" + GetTieuDe(nhomChuyenMuc.TenChuyenMuc) + "\" class=\"tag-element\"><span class=\"icon-tag icon-white\"></span>  " + nhomChuyenMuc.TenChuyenMuc + "</a>");

                // Lay if cua nhom chuyen muc 
                stringBuilder.Append("<div class=\"node-chuyen-muc\">");
                stringBuilder.Append("<div class=\"tieude-diemden\">");
                stringBuilder.Append("<a href=\"./" + nhomChuyenMuc.Id + "_" + GetTieuDe(nhomChuyenMuc.TenChuyenMuc) + "_chuyenmuc.aspx" + " \" id=" + GetTieuDe(nhomChuyenMuc.TenChuyenMuc) + ">" + nhomChuyenMuc.TenChuyenMuc + "</a>");
                stringBuilder.Append("</div>");
                int idCm = nhomChuyenMuc.Id;
                // Lay 4 dia diem thuoc chuyen muc
                int totalRows = 0;
                TList<DiaDiem> tlistDiadiem = DataRepository.DiaDiemProvider.GetPaged("IdChuyenMuc = " + idCm,
                                                                                      "UuTien DESC, NgayCapNhat DESC", 0,
                                                                                      4, out totalRows);
                // TList<DiaDiem> tlistDiadiem = DataRepository.DiaDiemProvider.GetByIdChuyenMuc(idCm, 0, 4);
                if (tlistDiadiem.Count() == 0)
                {
                    // 
                    stringBuilder.Append("<div class=\"diemden-element\">");
                    stringBuilder.Append("<p> Dữ liệu đang được cập nhật </p>");
                    stringBuilder.Append("</div>");
                }
                else
                {
                    // Duyet 4 dia diem nay
                    foreach (var diaDiem in tlistDiadiem)
                    {
                        stringBuilder.Append("<div class=\"diemden-element\">");
                        stringBuilder.Append("<div class=\"diemden-image\">");
                        stringBuilder.Append("<a href=" + "./" + diaDiem.Id + "_" + GetTieuDe(diaDiem.TenDiaDiem) +
                                             "_diadiem.aspx" + ">");
                        stringBuilder.Append("<img src=" + "./" + "Upload/SanPham/" + diaDiem.AnhDaiDien + " ></img>");
                        stringBuilder.Append("</a>");
                        stringBuilder.Append("</div>");
                        stringBuilder.Append("<div class=\"diemden-caption\">");
                        stringBuilder.Append("<p>");
                        stringBuilder.Append("<a href=" + "./" + diaDiem.Id + "_" + GetTieuDe(diaDiem.TenDiaDiem) +
                                             "_diadiem.aspx" + ">");
                        stringBuilder.Append("" + diaDiem.TenDiaDiem + "</a>");
                        stringBuilder.Append("</p>");
                        stringBuilder.Append("</div>");
                        stringBuilder.Append("<div class=\"phantram\">");
                        stringBuilder.Append("<span>" + diaDiem.PhanTram + "%" + "</span>");
                        stringBuilder.Append("</div>");
                        stringBuilder.Append("<div class=\"info-diadiem\">");
                        stringBuilder.Append("<p style=\"font-weight: bold\">Địa chỉ : </p>");
                        stringBuilder.Append("<span>" + diaDiem.DiaChi + "</span>");
                        /*stringBuilder.Append("<p style=\"font-weight: bold\">Tóm tắt : </p>");
                        stringBuilder.Append("<span>" + diaDiem.TomTat + "</span>");*/
                        stringBuilder.Append("</div>");
                        stringBuilder.Append("</div>");

                    }
                    //stringBuilder.Append("<div class=\"xem-tiep\">");
                    //stringBuilder.Append("<a class=\"rotate\" href=\"#\"><span class=\"icon-th icon-white\"></span></a>");
                    //stringBuilder.Append("</div>");
                }
                stringBuilder.Append("</div>");
            }
            stringDanhmuc.Append("</div>");
            litDiadiem.Text = stringBuilder.ToString();
            litDanhmuc.Text = stringDanhmuc.ToString();
        }
    }

}